# encoding: utf-8
from django.utils.safestring import mark_safe

import xadmin
from .models import GoodsCategory, Goods, GoodsImage, GoodsTags


class GoodsCategoryAdmin(object):
    # 后台展示的字段
    list_display = ['category_name', 'category_level', 'category_img', 'parent_category']
    # 提供条件搜索的字段
    search_fields = ['category_name', ]
    # 过滤筛选的字段
    list_filter = ['category_name', 'category_level']


xadmin.site.register(GoodsCategory, GoodsCategoryAdmin)


class GoodListAdmin(object):
    list_display = ["good_name", "click_num", "sold_num", "fav_num", "stock_num", "market_price",
                    "shop_price", "good_brief", "is_new", "is_hot"]
    search_fields = ['good_name', 'good_brief', 'tags__tag']
    list_editable = ["is_hot", "is_new"]
    list_filter = ["good_name", "click_num", "sold_num", "fav_num", "stock_num", "market_price",
                   "shop_price", "is_new", "is_hot", "good_category"]


xadmin.site.register(Goods, GoodListAdmin)


class GoodsImageAdmin(object):
    list_display = ["good", "image_path"]


xadmin.site.register(GoodsImage, GoodsImageAdmin)


class GoodsTagsAdmin(object):
    list_display = ["good", "tag"]


xadmin.site.register(GoodsTags, GoodsTagsAdmin)
